package cn.dckeji.gameBox.controller;


import cn.dckeji.gameBox.common.utils.DataUtil;
import cn.dckeji.gameBox.common.utils.ResultUtil;
import cn.dckeji.gameBox.dto.Result;
import cn.dckeji.gameBox.dto.UserStatis;
import cn.dckeji.gameBox.entity.Customer;
import cn.dckeji.gameBox.entity.Customer;
import cn.dckeji.gameBox.service.CustomerService;
import cn.dckeji.gameBox.service.LoginlogService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.xml.crypto.Data;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2018-08-20
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;


  @RequestMapping(value = "getCustomerSize",method = RequestMethod.POST)
    public Integer getCustomerSize(){
        List<Customer> customerList=customerService.selectList(null);
        return customerList.size();
    }

    @GetMapping("getCustomerList")
    public Map<String, Object> getCustomerList(Integer page, Integer limit,String nickName,String authTime,String loginTime){
        Page<Customer> customerPage = new Page<>();
        customerPage.setSize(limit);
        customerPage.setCurrent(page);
        EntityWrapper<Customer> entityWrapper = new EntityWrapper<>();
        if(StringUtils.isNotBlank(authTime)){
            String starttime = authTime.substring(0, 11);
            String enddate = authTime.substring(authTime.length() - 10);
            entityWrapper.between("authTime",starttime,enddate);
        }
        if(StringUtils.isNotBlank(loginTime)){
            String starttime = loginTime.substring(0, 11);
            String enddate = loginTime.substring(loginTime.length() - 10);
            entityWrapper.between("authTime",starttime+" 00:00:00",enddate+" 23:59:59");
        }
        if(StringUtils.isNotBlank(nickName)){
            entityWrapper.like("nickName",nickName);
        }
        entityWrapper.orderBy("loginTime",false);
        customerPage = customerService.selectPage(customerPage,entityWrapper);
        return ResultUtil.resultPage(customerPage.getTotal(),customerPage.getRecords());
    }
    @GetMapping("getLoginCount")
    public  Map<String, Object> getLoginCount(Integer page,Integer limit){
        Page<Map<String,Object>> pageList=customerService.getUserByDay(page,limit);
        return ResultUtil.resultPage(pageList.getTotal(),pageList.getRecords());
    }

}

